package com.hongkzh.www.adv.controller;

import com.hongkzh.www.adv.service.AdvService;
import com.hongkzh.www.adv.service.CarouselService;
import com.hongkzh.www.adv.service.EnterpriseAdvService;
import com.hongkzh.www.conmon.ReqResponse;
import com.hongkzh.www.swagger.annotation.*;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * @author martins
 */
@Api(tag = "enterpriseAdv", description = "企业广告")
public class EnterpriseAdvController extends Controller {
    static EnterpriseAdvService enterpriseAdvService=new EnterpriseAdvService();
    static CarouselService carouselService=new CarouselService();
    static AdvService advService=new AdvService();

    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseCarouselList", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告轮播图")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ imgSrc 图片地址 ,imgLinks 图片链接 imgRank 图片排序  }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getEnterpriseCarouselList(){
        ReqResponse<List<Record>> r=new ReqResponse();
        List<Record>  record= carouselService.getEnterpriseCarouselList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseCategoryList", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告分类列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{   name 标题   id 类别id }"),
                    @ResponseHeader(name="msg",description = "失败原因") })
    })
    public void getEnterpriseCategoryList(){
        ReqResponse< List<Record>> r=new ReqResponse();
        List<Record>  record= enterpriseAdvService.getEnterpriseCategoryList();
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseHotAdvTypeList", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告热度类型列表")
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{   title 标题 subtitle 副标题 typeId 热度类型id   currentTime 当前时间 beginDate 开始时间 endDate 结束时间 sortDate 离现在时间}"),
                    @ResponseHeader(name="msg",description = "失败原因") })
    })
    public void getEnterpriseHotAdvTypeList(){
        ReqResponse< List<Record>> r=new ReqResponse();
         List<Record>  record= enterpriseAdvService.getEnterpriseHotAdvTypeList();
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseHotAdvList", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告热度列表")
    @Params({
            @Param(name = "typeId", description = "企业广告热度类型id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{vedioLength 视频长度 showType 1视频 2网页 content 网页内容 coverImgSrc 图片地址   imgRank 图片排序 title 标题  playCount 观看总数   costCount 消费总数 integralCount 总积分数 lastCount 剩余积分 percentage 百分比 uid 用户id  uName 用户名称 headImg  用户头像   }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })
    })
    public void getEnterpriseHotAdvList(){
        String id=getPara("typeId");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse< Page<Record>> r=new ReqResponse();
        Page<Record>  record= enterpriseAdvService.getEnterpriseHotAdvList(id,pageNumber);
        r.setData(record);
        renderJson(r);
    }



/*
    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseCategoryAdvList", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告具体分类页  列表")
    @Params({
            @Param(name = "id", description = "分类id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string"),
            @Param(name = "sortId", description = "排序字段 默认排序 rank  最多浏览 play_count  最新上传 create_date ", required = false, dataType = "string"),
            @Param(name = "sortValue", description = "排序值 asc 升 desc 降 ", required = false, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{ coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题   headImg 头像   uid 用户id  uName 用户名 shareCount分享总数  praiseCount点赞总数 }]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getEnterpriseCategoryAdvList(){
        String cid=getPara("id");
        int pageNumber=getParaToInt("pageNumber");
        String sortId=getPara("sortId");
        String sortValue=getPara("sortValue");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= enterpriseAdvService.getEnterpriseCategoryAdvList(cid,pageNumber,sortId,sortValue);
        r.setData(record);
        renderJson(r);
    }*/

    @ApiOperation(url = "/v1/enterpriseAdv/getEnterpriseAdvById", tag = "enterpriseAdv", httpMethod = "post",description = "获取企业广告视频信息")
    @Params({
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  {historyId 前一个历史播放记录  playCount 播放总数 praiseCount 点赞总数 follows 关注数 collectionState 已经收藏 1   没收藏 0 praiseState 已经点赞 1  没点赞 0  uid 用户id uName  用户名称 headImg 用户头像  coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题  type 类型  1自媒体 2企业广告3城市广告4传统文化  createDate 创建时间 circle 圈子数} "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getEnterpriseAdvById(){
        String id=getPara("id");
        ReqResponse<Record> r=new ReqResponse();
        String loginUid=getPara("loginUid");
        Record record= advService.getAdvById(id,loginUid);

        if(null!=record){
            record.set("recommends",null);
            List<Record> recommends= advService.getAdvRecommendByAdvId(id);
            if(null!=recommends) {
                record.set("recommends", recommends);
            }
            record.set("historyId","");
            Record history= advService.historyEnterpriseAdv(id,loginUid);
            if(null!=history){
                record.set("historyId",history.get("id"));
            }
            r.setData(record);
        }
        else{
            r.setCode(1);
            r.setMsg("内容已下线或者不存在");
        }

        renderJson(r);
    }
    @ApiOperation(url = "/v1/enterpriseAdv/collection", tag = "enterpriseAdv", httpMethod = "post",description = "通过用户id   视频id  state收藏状态 1收藏0取消收藏")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "state", description = "收藏状态 1收藏0取消收藏", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="data",description = " 总收藏数"),
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })

    public void collection(){
        EnterpriseAdvService enterpriseAdvService2 = enhance(EnterpriseAdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        String state=getPara("state");
        ReqResponse<String> r=new ReqResponse();
        try {
              r.setData(enterpriseAdvService2.collection(loginUid,id,state));

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
            r.setMsg("操作失败");
        }
        renderJson(r);
    }

    @ApiOperation(url = "/v1/enterpriseAdv/praise", tag = "enterpriseAdv", httpMethod = "post",description = "通过用户id   视频id  state点赞状态 1点赞0取消点赞")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "state", description = "点赞状态 1点赞0取消点赞", required = true, dataType = "string"),
            @Param(name = "id", description = "视频id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="data",description = " 总点赞数"),
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })

    public void praise(){
        EnterpriseAdvService enterpriseAdvService2 = enhance(EnterpriseAdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        String state=getPara("state");
        ReqResponse<String> r=new ReqResponse();
        try {
            r.setData(enterpriseAdvService2.praise(loginUid,id,state));

        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
            r.setMsg("操作失败");
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/enterpriseAdv/endPlayEnterpriseAdvById", tag = "enterpriseAdv", httpMethod = "post",description = "播放完成给用户的积分")
    @Params({
            @Param(name = "id", description = "视频id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " integral 得到积分 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void endPlayEnterpriseAdvById(){
        AdvService advService2 = enhance(AdvService.class);
        String loginUid=getPara("loginUid");
        String id=getPara("id");
        ReqResponse<Record> r=new ReqResponse();
        try {
            Record record = advService2.endPlayEnterpriseAdvById(loginUid, id);

            r.setData(record);
        }catch (Exception e){
            r.setCode(1);

        }
        renderJson(r);
    }

}
